package com.ruoyi.community.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.druid.support.json.JSONUtils;
import com.ruoyi.community.domain.vo.TripVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.Trip;
import com.ruoyi.community.service.ITripService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 行程Controller
 *
 * @author lj
 * @date 2022-02-24
 */
@RestController
@RequestMapping("/community/trip")
public class TripController extends BaseController
{
    @Autowired
    private ITripService tripService;

    /**
     * 查询行程列表
     */
    @PreAuthorize("@ss.hasPermi('community:trip:list')")
    @GetMapping("/list")
    public TableDataInfo list(Trip trip)
    {
        startPage();
        List<TripVo> list = tripService.selectTripListVo(trip);
        return getDataTable(list);
    }

    /**
     * 导出行程列表
     */
    @PreAuthorize("@ss.hasPermi('community:trip:export')")
    @Log(title = "行程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Trip trip)
    {
        List<Trip> list = tripService.selectTripList(trip);
        ExcelUtil<Trip> util = new ExcelUtil<Trip>(Trip.class);
        util.exportExcel(response, list, "行程数据");
    }

    /**
     * 获取行程详细信息
     */
    @PreAuthorize("@ss.hasPermi('community:trip:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tripService.selectTripById(id));
    }

    /**
     * 新增行程
     */
    @PreAuthorize("@ss.hasPermi('community:trip:add')")
    @Log(title = "行程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Trip trip)
    {
        return toAjax(tripService.insertTrip(trip));
    }

    /**
     * 修改行程
     */
    @PreAuthorize("@ss.hasPermi('community:trip:edit')")
    @Log(title = "行程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Trip trip)
    {
        return toAjax(tripService.updateTrip(trip));
    }

    /**
     * 删除行程
     */
    @PreAuthorize("@ss.hasPermi('community:trip:remove')")
    @Log(title = "行程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tripService.updateTripByIds(ids));
    }
    @ApiOperation("删除测试")
    @DeleteMapping("delete")
    public AjaxResult removes(@RequestBody Long ids)
    {
          //JSONUtils.parse(ids);
        return toAjax(1);
    }
}
